-
Notifications
You must be signed in to change notification settings - Fork 134
/
UpNextLargeWidgetView.swift
134 lines (120 loc) · 5.1 KB
/
UpNextLargeWidgetView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import Foundation
import SwiftUI
struct UpNextLargeWidgetView: View {
@State var episodes: [WidgetEpisode]
@State var filterName: String?
@State var isPlaying: Bool
var body: some View {
if filterName != nil {
LargeFilterView(episodes: $episodes, filterName: $filterName)
} else {
LargeUpNextWidgetView(episodes: $episodes, isPlaying: $isPlaying)
}
}
}
struct LargeUpNextWidgetView: View {
@Binding var episodes: [WidgetEpisode]
@Binding var isPlaying: Bool
var body: some View {
guard let firstEpisode = episodes.first else {
return AnyView(EmptyView())
}
return AnyView(
GeometryReader { geometry in
VStack(alignment: .leading, spacing: 0) {
ZStack {
Rectangle().fill(Color.clear)
.lightBackgroundShadow()
.frame(width: .infinity, height: .infinity)
HStack(alignment: .top) {
EpisodeView(episode: firstEpisode, topText: isPlaying ? Text(L10n.nowPlaying.localizedUppercase) : Text(L10n.podcastTimeLeft(CommonWidgetHelper.durationString(duration: firstEpisode.duration)).localizedUppercase))
Spacer()
Image("logo_red_small")
.frame(width: 28, height: 28)
.unredacted()
}
}
.padding(16)
.frame(height: geometry.size.height * 82 / 345)
ZStack {
Rectangle().fill(darkBackgroundColor)
VStack(alignment: .leading, spacing: 10) {
if episodes.count > 1 {
ForEach(episodes[1 ... min(4, episodes.count - 1)], id: \.self) { episode in
EpisodeView(episode: episode, topText: Text(CommonWidgetHelper.durationString(duration: episode.duration)))
.frame(height: geometry.size.height * 50 / 345)
}
}
if episodes.count < 5 {
if episodes.count > 1 {
if episodes.count != 4 {
Spacer().frame(height: 1)
}
Divider()
.background(Color(UIColor.opaqueSeparator))
}
if episodes.count != 4 {
Spacer()
}
HStack {
Spacer()
HungryForMoreView()
Spacer()
}
Spacer()
}
}
.padding(16)
.frame(width: .infinity, height: .infinity, alignment: .center)
}
}
})
}
}
struct LargeFilterView: View {
@Binding var episodes: [WidgetEpisode]
@Binding var filterName: String?
var body: some View {
guard episodes.first != nil else {
return AnyView(EmptyView())
}
return AnyView(
VStack(alignment: .leading, spacing: 0) {
VStack(spacing: 0) {
HStack(alignment: .top) {
if let filterName = filterName {
Text(filterName)
.font(.callout)
.fontWeight(.regular)
.foregroundColor(Color.secondary)
.frame(height: 18)
}
Spacer()
Image("logo_red_small")
.frame(width: 28, height: 28)
.unredacted()
}
.frame(height: 32)
VStack(alignment: .leading, spacing: 10) {
ForEach(episodes[0 ... min(4, episodes.count - 1)], id: \.self) { episode in
HStack {
EpisodeView.createCompactWhenNecessaryView(episode: episode)
.frame(minHeight: 42, maxHeight: 56)
Spacer()
}
}
}
}.padding(16)
.background(Rectangle().fill(Color.clear)
.lightBackgroundShadow())
if episodes.count < 5 {
ZStack {
Rectangle()
.fill(darkBackgroundColor)
HungryForMoreView()
}
}
}
)
}
}